package com.sky.order.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.temp.OrdersTemp;
import com.sky.temp.SalesTop10Temp;
import com.sky.temp.TurnoverTemp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders order);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 订单分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer status);


    Integer countByStatusAndDate(Integer status,LocalDate date);

    @Select("select * from orders where status = #{pendingPayment} and order_time< #{localDateTime}")
    List<Orders> getTimeOutOrder(Integer pendingPayment, LocalDateTime localDateTime);

    @Select("select * from orders where status = #{deliveryInProgress} and order_time<#{time}")
    List<Orders> getByStatusAndOrdertimeLT(Integer deliveryInProgress, LocalDateTime time);


    List<TurnoverTemp> turnoverStatistics(LocalDate begin,LocalDate end,Integer status);

    /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     */
    List<OrdersTemp> ordersStatistics(LocalDate begin, LocalDate end,Integer status);

    /**
     * 查询销量排名top10
     * @param begin
     * @param end
     * @return
     */
    List<SalesTop10Temp> getSalesTop10(LocalDate begin,LocalDate end);
}
